package com.example.boot.rabbitmq.customer.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @author ccubee
 * @since 21-3-9 20:15
 */
@Slf4j
@Component
public class TopicListener {

    /**
     * 使用 ${} 绑定
     * 使用type 申明 exchange类型
     * @param message 消息
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "${rabbit.topic.topicQueue}"),
            exchange = @Exchange(value = "${rabbit.topic.topicExchange}",
            type = "topic"),
            key = "${rabbit.topic.topicKey}")
    )
    @RabbitHandler
    public void onMessage(Message message){
        log.info("receive message {}", new String(message.getBody(), StandardCharsets.UTF_8));

    }
}
